import ShopCategory from '@/types/entity/DishCategory'
import type { Option, SurveyItem } from '@/components/check-box/check-box-selector/type'
import $API from '@/api'
import { ReceivingMethod, receivingMethodLabelOf } from '@/enum/ReceivingMethod'
const cache: { [key: string]: Option[] } = {
  shopCategory: []
}

const shopCheckBoxOperation: SurveyItem[] = [
  {
    label: '排序方式',
    name: 'sort',
    options: [
      {
        label: '距离最近',
        value: 1
      },
      {
        label: '销量最高',
        value: 2
      }
    ],
    isMultipleChoice: false,
    value: 1
  },

  {
    label: '收餐方式',
    name: 'businessType',
    options: [
      {
        label: receivingMethodLabelOf(ReceivingMethod.SELF_PICKUP),
        value: ReceivingMethod.SELF_PICKUP
      },
      {
        label: receivingMethodLabelOf(ReceivingMethod.SHOP_EAT),
        value: ReceivingMethod.SHOP_EAT
      },
      {
        label: receivingMethodLabelOf(ReceivingMethod.DELIVERY),
        value: ReceivingMethod.DELIVERY
      }
    ],
    isMultipleChoice: false,
    value: null
  },
  {
    label: '店铺分类',
    name: 'shopCategory',
    options: [],
    isInitialized: false,
    initOptions: async (): Promise<Option[]> => {
      if (cache.shopCategory.length > 0) {
        return cache.shopCategory
      }
      const result = await $API.shopCategory.list()
      if (result.success) {
        return (cache.shopCategory = result.data.map((shopCategory: ShopCategory) => {
          return { label: shopCategory.name, value: shopCategory.id }
        }))
      }
      return []
    },
    isMultipleChoice: false,
    value: null
  },
  {
    label: '店铺标签',
    name: 'reputation',
    options: [
      {
        label: '品牌连锁',
        value: '1-'
      },
      {
        label: '优选',
        value: '2-'
      },
      {
        label: '新店',
        value: '3-'
      }
    ],
    isMultipleChoice: true,
    value: []
  }
]

export default shopCheckBoxOperation
